/*************************************************************************
	> File Name: 7.368E.cpp
	> Author: hug
	> Mail: hug@haizeix.com
	> Created Time: 一  2/10 21:19:51 2025
 ************************************************************************/

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct Events {
    int v, t, ind;
    int dep;
};

int n, m;
vector<Events> arr;
int d[200005];
int x[200005];

bool cmp(Events a, Events b) {
    if (a.t - b.t) return a.t < b.t;
    return a.dep < b.dep;
}

int main() {
    cin >> n >> m >> x[1];
    for (int i = 1, a, b, s, t; i <= m; i++) {
        cin >> a >> b >> s >> t;
        arr.push_back({a, s, i, 1});
        arr.push_back({b, t, i, 0});
    }
    sort(arr.begin(), arr.end(), cmp);
    for (auto eve : arr) {
        if (eve.dep) {
            x[eve.ind] = max(x[eve.ind], d[eve.v] - eve.t);
        } else {
            d[eve.v] = max(d[eve.v], eve.t + x[eve.ind]);
        }
    }
    for (int i = 2; i <= m; i++) {
        if (i > 2) cout << " ";
        cout << x[i];
    }
    cout << endl;
    return 0;
}
